<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */
?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>

<?php
$brandId = $_product->getBrand();
$productId = $_product->getId();
$sameBrandProducts = Mage::getResourceModel('catalog/product_collection')
                        ->addAttributeToSelect(array('small_image','name','price'))
                        ->addAttributeToFilter('visibility', array('neq' => 1))
                        ->addAttributeToFilter('status', 1)
                        ->addAttributeToFilter('entity_id', array('neq' => $productId))
                        ->addAttributeToFilter('brand',$brandId)
                        ->setCurPage(1)
                        ->setPageSize(4);
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->sameBrandProducts);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($sameBrandProducts);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($sameBrandProducts);
?>


<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
<div class="product-view">
    <div class="product-essential li-prodetail">
    
        <?php echo $this->getBlockHtml('formkey') ?>
        <div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>

        <div class="product-shop">
            <div class="product-name">
                <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
            </div>
	        <div class="li-product-date">
	        	<?php 
	        		$proid = $_product->getId();
                	$pro = Mage::getModel('catalog/product')->load($proid);
	        	 ?>
	        	<?php if($pro->getpromotion()): ?>
					<h1><?php echo $pro->getpromotion();?></h1>
				<?php endif; ?>
	        </div>
	        <!-- Get Product All Price -->
			<div class="li-product-info">
				<?php if(floatval($_product->getPrice()) !== floatval($_product->getFinalPrice())): ?>
					<div class="li-chuxiao-info">
						<strong>原价</strong><span style="text-decoration: line-through">
							￥<?php echo $_product->getPrice(); ?>
						</span>
					</div>
					<div class="li-chuxiao-info">
						<strong>促销价</strong>
							<span style="color: #c40000;position: relative;top: -18px;">
								￥
								<i><?php echo number_format($_product->getFinalPrice(),2) ?></i>
							</span>
					</div>
				<?php else: ?>
					<div class="li-chuxiao-info">
					<strong>价格</strong>
						<span style="color: #c40000;position: relative;top: -18px;">
							￥
							<i><?php echo number_format($_product->getPrice(),2) ?></i>
						</span>
					</div>
				<?php endif; ?>

				<!-- Product Promotion Start -->
				<!-- <div class="li-chuxiao-info">
					<strong>促销活动</strong>
					<div class="li-chuxiao-item">
						<strong>买票</strong><span>买即送旺旺小小酥60g*8袋（口味随机）</span>
						<strong style="clear: both;">积分</strong><span>双倍积分</span>
					</div>
				</div> -->
				<!-- Product Promotion End -->
				
				<div class="li-erweima">
					<!-- Get Product QR code -->
					<img src="<?php echo Mage::getBaseUrl() . 'admin_zgb/qr/render/sku/' . $_product->getSku(); ?>"/>
					<div class="li-erweima-tip">
						客户端扫购更便捷
					</div>
				</div>
			</div>
            <?php
                $tags = Mage::helper('zgb')->getProductInfoTags($_product);
                if($tags):
                foreach($tags as $tag):
            ?>
                <span class="product-info-tags" ><?php echo $tag; ?></span>
            <?php endforeach; ?>
            <?php endif; ?>
            <?php // echo $this->getReviewsSummaryHtml($_product, false, true)?>
            <?php // echo $this->getChildHtml('alert_urls') ?>

            <?php // echo $this->getTierPriceHtml() ?>
            <div class="product-price" style="display: none">
	            <?php echo $this->getChildHtml('product_type_data') ?>
	                <?php
	                $proid = $_product->getId();
	                $pro = Mage::getModel('catalog/product')->load($proid);
	                ?>
	                <?php if($pro->getpromotion()):?>
	            <div class="promo-msg">
	                <span><?php echo $pro->getpromotion();?></span>
	            </div>
	                <?php endif;?>
	            <?php echo $this->getChildHtml('extrahint') ?>
            </div>



            <div class="addToCart" style="margin-top: 20px" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
                <div class="line">
                <span class="title">数量</span>
                <span class="fa nfa-minus num-down" id="num-down"></span>
                <span class="qty-span"><input type="text" name="qty" class="pnum" id="qty"/></span>
                <span class="fa nfa-plus num-up" id="num-up"></span>
                </div>
                <!-- Not This Method By Product -->
				<!-- <a class="li-lijigoumai">立即购买</a> -->
                <button class="li-jiarugouwuche add-to-cart-button">加入购物车</button>
            </div>

            <?php $_product = $this->getProduct(); ?>
            <?php $_wishlistSubmitUrl = $this->helper('wishlist')->getAddUrl($_product); ?>

            <ul class="add-to-links" style="display: none">
            <?php if ($this->helper('wishlist')->isAllow()) : ?>
                <li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, this.href); return false;" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
            <?php endif; ?>

            <?php echo $this->getChildHtml('other');?>

            <?php if ($_product->isSaleable() && $this->hasOptions()):?>
                <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
            <?php endif;?>

        </div>

        <div class="product-img-box">
            <?php echo $this->getChildHtml('media') ?>
        </div>

        <div class="clearer"></div>
        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
        <?php endif;?>
    
    
    </div>
    <script src="<?php echo $this->getSkinUrl('js/jquery.flexslider-min.js') ?>"></script>
<style>
	.li-youlike li{
		width: 150px;
	}
	.carousel.flexslider{
		border: 1px solid #D1D1D1;
		border-top: none;
	}
	.flex-direction-nav{
		top:40%;
	}
</style>

    <div class="li-tab" style="margin-top: 20px">
    <a class="active">猜你喜欢<span class="li-tab-caret"></span><span class="line active"></span></a>
    <a href="<?php echo Mage::getBaseUrl() . 'admin_zgb/recent/index/'?>">最近进货<span class="li-tab-caret"></span> <span class="line"></span></a>
    </div>
    <div class="li-line"></div>
    <div class="carousel flexslider">
    	<!-- for show other product Start -->
    	<?php 
 			$randProducts = Mage::getModel('catalog/product')
 				->getCollection();
 			Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($randProducts);
			Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($randProducts);
			Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($randProducts);
			$randProducts->getSelect()->limit(10)->order("rand()")

    	?>
	    <ul class="li-youlike slides">
			<?php
			foreach($randProducts as $_rand){
	    			$thisproduct= Mage::getModel('catalog/product')->load($_rand->getId());
	    			?>
				    <li>
					    <div class="li-protouter">
					        <a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" class="li-proimg">
					        	<img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(200) ?>"/></a>
					        <strong>
					        ￥
					        	<?php echo number_format($thisproduct->getPrice(),2); ?>
					        </strong>
					        <h2>
					        	<?php echo $thisproduct->getName(); ?>
					        </h2>
					        <div class="li-bottom addToCart" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$thisproduct->getId())); ?>">
								<div class="li-bottom-left">
									<span class="reduce">-</span>
									<div class="li-input"><input type="text" name="qty" class="pnum" value="1"/></div>
									<span class="add">+</span>
								</div>
								<button class="li-bottom-right li-add-car">加入购物车</button>
							</div>
					    </div>
				    </li>
	    		<?php } ?>
		</ul>
	    <!-- for show other product End -->
	</div>
</div>
<script>
	(function($){
	//推荐商品滚动展示
	$(".flexslider").flexslider({
	animation: "slide",
	animationLoop: true,
	itemWidth:150,
	directionNav: true,
	controlNav: false,
	pauseOnHover: true,
	prevText: "",
	nextText: "",
	minItems: 5,
	maxItems: 5
	});
	})(jQuery)
</script>
